﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace QueryControl
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:QueryControl runat=server></{0}:QueryControl>")]
    public class QueryControl : CompositeControl
    {
        private HyperLink linkQuery;
        private Label labelQueryRank;

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Description("Query text")]
        public string QueryText
        {
            get
            {
                EnsureChildControls();
                return linkQuery.Text;
            }
            set
            {
                EnsureChildControls();
                linkQuery.Text = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Description("Query link")]
        public string QueryLink
        {
            get
            {
                EnsureChildControls();
                return linkQuery.NavigateUrl;
            }
            set
            {
                EnsureChildControls();
                linkQuery.NavigateUrl = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Description("Query rank text")]
        public string QueryRankText
        {
            get
            {
                EnsureChildControls();
                return labelQueryRank.Text;
            }
            set
            {
                EnsureChildControls();
                labelQueryRank.Text = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Description("Query rank color")]
        public Color QueryRankColor
        {
            get
            {
                EnsureChildControls();
                return labelQueryRank.BackColor;
            }
            set
            {
                EnsureChildControls();
                labelQueryRank.BackColor = value;
            }
        }


        protected override void CreateChildControls()
        {
            linkQuery = new HyperLink();

            labelQueryRank = new Label();

            this.Controls.Add(linkQuery);
            this.Controls.Add(labelQueryRank);
        }


        protected override void Render(HtmlTextWriter writer)
        {
            writer.RenderBeginTag(HtmlTextWriterTag.Table);
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            linkQuery.RenderControl(writer);
            writer.RenderEndTag();
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            labelQueryRank.RenderControl(writer);
            writer.RenderEndTag();
            writer.RenderEndTag();
        }
    }
}
